import Vue from "vue"
import Vuex from "vuex"
import {
	GetUserInfo,
	task
} from '@/api/index.js'

Vue.use(Vuex)

import Home from "./Home/index"
import SongSheetInfo from './SongSheetInfo/index'
import Login from './Login/index.js'
import song from './song/index.js'
import search from './search/index.js'
import video from './video/index.js'
import search_list from './search_list/index.js'
import RecentPlays from './RecentPlays/index.js'
import follow from './follow/index.js'
import song_sheet from './song_sheet/index.js'

//准备actions对象——响应组件中用户的动作
const actions = {
	// 获取账号信息
	async GetUserInfo(state, nid) {
		let info = await GetUserInfo(nid)
		if (info['code'] === 200) {
			state.commit('setUserInfo', info['profile'])
		}
	},

	async task(state) {
		await task()
	}
}
//准备mutations对象——修改state中的数据
const mutations = {
	// 修改用户信息
	setUserInfo(state, obj) {
		state.UserInfo = obj
	}
}
//准备state对象——保存具体的数据
const state = {
	UserInfo: {} // 用户信息
}

export default new Vuex.Store({
	state,
	mutations,
	actions,
	modules: {
		Home, // 首页
		SongSheetInfo, // 歌单信息
		Login, // 登录
		song, // 歌曲播放页面
		search, // 搜索组件
		video, // 视频	
		search_list, // 搜索结果列表
		RecentPlays, // 最近播放
		follow, // 粉丝和关注
		song_sheet, // 歌单广场
	}
})
